#!/bin/bash

s1_read_last_two_bytes_of_a_mbr_backup_file(){
	file_path=$1
	last_two_bytes=$(tail -c 2 $file_path)
	if [[$last_two_bytes == "55AA"]];then
		echo "YES"
	else
		echo "NO"
	fi
}

s2_read_mbr_partition_table_info(){
	file_path=$1
	start_sector=$(xxd -e -s 0x1BE -| 4 $file_path| bc)
	end_sector=$(xxd -e -s 0x1CE -| 4 $file_path | bc)
	echo "$start_sector $end_sector"
}


s3_parse_partition_info() {
	while read line;do
		disk_size=$(echo $line | awk '{print $2}')
		disk_size_sectors=$(echo $line |awk '{print $4}')
		physical_sector_size=$(echo $line | awk '{print $6}')
		first_partition_start=$(echo $line | awk '{print $8}')
		first_partition_end=$(echo $line | awk '{print $9}')
		first_partition_type=$(echo $Line | awk '{print $10}')

		echo "disk size in bytes:$disk_size"
		echo "disk size in sectors:$disk_size_sectors"
		echo "physical sector size in bytes:$physical_sector_size"
		echo "first partition start sector id:$first_partition_start"
		echo "first partition end sector id:$first_partition_end"
		echo "first partition type:$first_partition_type"
	done
}

s4_run_passwd_as_plain_user_and_get_status(){
	oversleeping_path=$(which oversleeping)
	chown root:root $oversleeping_path
	chmod 755 $oversleeping_path
	chmod u+s $oversleeping_path
	nohup oversleeping & 
	pid=$!
	sleep 1
	uid=$(ps -o uid= -p $pid)
	euid=$(ps -o euid= -p $pid)
	ruid=$(ps -o ruid= -p $pid)
	usernameA=$(id -un $uid)
	usernameB=$(id -un $euid)
	usernameC=$(id -un $ruid)
	echo "$uid,$euid,$ruid"
	echo "$usernameA,$usernameB,$usernameC"
}

s5_add_a_scheduled_task(){
	crontab -| >mycron
	echo "*/5***date'+%Y%m%d_%H%M%S'>>$HOME/test_crontab">>mycron
	crontab mycron
	rm mycron
}


